package com.cskaoyan.controller;


import com.cskaoyan.bean.Category;
import com.cskaoyan.service.CategoryService;
import com.cskaoyan.vo.BaseRespVo;
import com.cskaoyan.vo.CategoryL1VO;
import com.cskaoyan.vo.CategoryList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class CategoryController {

    @Autowired
    CategoryService categoryService;
    @RequestMapping("admin/category/list")
    public BaseRespVo queryCategory(){
        List<CategoryList> categoryLists =  categoryService.querylist();
        return BaseRespVo.ok(categoryLists);
    }
    @RequestMapping("admin/category/l1")
    public BaseRespVo queryCategoryL1(){
        List<CategoryL1VO> categories =  categoryService.queryL1();
        return BaseRespVo.ok(categories);
    }
    @RequestMapping("admin/category/delete")
    public BaseRespVo deleteCategory(@RequestBody Category category){

        categoryService.deleteCategory(category);

        return BaseRespVo.ok();
    }
    @RequestMapping(value = "admin/category/create")
    public BaseRespVo create(@RequestBody Category category){
        Category category1  = categoryService.create(category);
        return BaseRespVo.ok(category1);
    }
    @RequestMapping("admin/category/update")
    public BaseRespVo update(@RequestBody Category category){
        categoryService.update(category);
        return BaseRespVo.ok();
    }

//    @RequestMapping("admin/category/create")
//
//    public BaseRespVo createCategory(@RequestBody Category category ){
//
//        categoryService.createCategory(category);
//    }
}
